local lib = {}

lib.ui = {}
lib.ui.button = require('UI/button')
lib.ui.row = require('UI/row')
lib.ui.column = require('UI/column')
lib.ui.label = require('UI/label')
lib.ui.scroll = require('UI/scroll')

function lib.render(t, x_pos, y_pos, max_width, max_height)
	for i = 1, #t do
		if t[i].color ~= nil then love.graphics.setColor(t[i].color) else love.graphics.setColor(1,1,1,0) end

		local var = {
			x_pos = x_pos,
			y_pos = y_pos,
			max_width = max_width,
			max_height = max_height,
		}
		
		var = lib.ui[t[i].name](var, lib, t, i)
		
		if var ~= nil then
			x_pos = var.x_pos
			y_pos = var.y_pos
			max_width = max_width
			max_height = max_height
		end
	end
end

font = love.graphics.newFont(16)
love.graphics.setFont(font)

if love.system.getOS() == 'Android' then
	love.window.setFullscreen(true)
end

x_ = 0
y_ = 0
dx_ = 0
dy_ = 0
in_ = 0
y_start = 0

function love.touchmoved( id, x, y, dx, dy, pressure )
	x_ = x
	y_ = y
	dx_ = dx
	dy_ = dy
end

function love.wheelmoved(x, y)
	y_start = y_start + y * 30
end

function lib.update()
	local mx, my = -1, -1
	if love.system.getOS() == 'Android' and mx or -1 >= 0 then
		local touches = love.touch.getTouches()
		
		for i, id in ipairs(touches) do
			local x, y = love.touch.getPosition(id)
			mx = x
			my = y
		end 
	else
		mx, my = love.mouse.getPosition()
	end

	if dy_ ~= 0 then
		y_start = y_start + dy_
		dy_ = 0
	end

	return mx, my
end

function lib._end_() y_start = 0 end

return lib